package gii

import (
	"bytes"
	"reflect"
	"store/libs/helper"
	"store/models/base"
	"strings"
)

var (
	mdT = `<!DOCTYPE html>
<html>
<head>
<title>gii</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">

<style>
/* https://github.com/microsoft/vscode/blob/master/extensions/markdown-language-features/media/markdown.css */
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

body {
	font-family: var(--vscode-markdown-font-family, -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif);
	font-size: var(--vscode-markdown-font-size, 14px);
	padding: 0 26px;
	line-height: var(--vscode-markdown-line-height, 22px);
	word-wrap: break-word;
}

#code-csp-warning {
	position: fixed;
	top: 0;
	right: 0;
	color: white;
	margin: 16px;
	text-align: center;
	font-size: 12px;
	font-family: sans-serif;
	background-color:#444444;
	cursor: pointer;
	padding: 6px;
	box-shadow: 1px 1px 1px rgba(0,0,0,.25);
}

#code-csp-warning:hover {
	text-decoration: none;
	background-color:#007acc;
	box-shadow: 2px 2px 2px rgba(0,0,0,.25);
}

body.scrollBeyondLastLine {
	margin-bottom: calc(100vh - 22px);
}

body.showEditorSelection .code-line {
	position: relative;
}

body.showEditorSelection .code-active-line:before,
body.showEditorSelection .code-line:hover:before {
	content: "";
	display: block;
	position: absolute;
	top: 0;
	left: -12px;
	height: 100%;
}

body.showEditorSelection li.code-active-line:before,
body.showEditorSelection li.code-line:hover:before {
	left: -30px;
}

.vscode-light.showEditorSelection .code-active-line:before {
	border-left: 3px solid rgba(0, 0, 0, 0.15);
}

.vscode-light.showEditorSelection .code-line:hover:before {
	border-left: 3px solid rgba(0, 0, 0, 0.40);
}

.vscode-light.showEditorSelection .code-line .code-line:hover:before {
	border-left: none;
}

.vscode-dark.showEditorSelection .code-active-line:before {
	border-left: 3px solid rgba(255, 255, 255, 0.4);
}

.vscode-dark.showEditorSelection .code-line:hover:before {
	border-left: 3px solid rgba(255, 255, 255, 0.60);
}

.vscode-dark.showEditorSelection .code-line .code-line:hover:before {
	border-left: none;
}

.vscode-high-contrast.showEditorSelection .code-active-line:before {
	border-left: 3px solid rgba(255, 160, 0, 0.7);
}

.vscode-high-contrast.showEditorSelection .code-line:hover:before {
	border-left: 3px solid rgba(255, 160, 0, 1);
}

.vscode-high-contrast.showEditorSelection .code-line .code-line:hover:before {
	border-left: none;
}

img {
	max-width: 100%;
	max-height: 100%;
}

a {
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

a:focus,
input:focus,
select:focus,
textarea:focus {
	outline: 1px solid -webkit-focus-ring-color;
	outline-offset: -1px;
}

hr {
	border: 0;
	height: 2px;
	border-bottom: 2px solid;
}

h1 {
	padding-bottom: 0.3em;
	line-height: 1.2;
	border-bottom-width: 1px;
	border-bottom-style: solid;
}

h1, h2, h3 {
	font-weight: normal;
}

table {
	border-collapse: collapse;
}

table > thead > tr > th {
	text-align: left;
	border-bottom: 1px solid;
}

table > thead > tr > th,
table > thead > tr > td,
table > tbody > tr > th,
table > tbody > tr > td {
	padding: 5px 10px;
}

table > tbody > tr + tr > td {
	border-top: 1px solid;
}

blockquote {
	margin: 0 7px 0 5px;
	padding: 0 16px 0 10px;
	border-left-width: 5px;
	border-left-style: solid;
}

code {
	font-family: Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback";
	font-size: 1em;
	line-height: 1.357em;
}

body.wordWrap pre {
	white-space: pre-wrap;
}

pre:not(.hljs),
pre.hljs code > div {
	padding: 16px;
	border-radius: 3px;
	overflow: auto;
}

pre code {
	color: var(--vscode-editor-foreground);
	tab-size: 4;
}

/** Theming */

.vscode-light pre {
	background-color: rgba(220, 220, 220, 0.4);
}

.vscode-dark pre {
	background-color: rgba(10, 10, 10, 0.4);
}

.vscode-high-contrast pre {
	background-color: rgb(0, 0, 0);
}

.vscode-high-contrast h1 {
	border-color: rgb(0, 0, 0);
}

.vscode-light table > thead > tr > th {
	border-color: rgba(0, 0, 0, 0.69);
}

.vscode-dark table > thead > tr > th {
	border-color: rgba(255, 255, 255, 0.69);
}

.vscode-light h1,
.vscode-light hr,
.vscode-light table > tbody > tr + tr > td {
	border-color: rgba(0, 0, 0, 0.18);
}

.vscode-dark h1,
.vscode-dark hr,
.vscode-dark table > tbody > tr + tr > td {
	border-color: rgba(255, 255, 255, 0.18);
}

</style>

<style>
/* Tomorrow Theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Original theme - https://github.com/chriskempson/tomorrow-theme */

/* Tomorrow Comment */
.hljs-comment,
.hljs-quote {
	color: #8e908c;
}

/* Tomorrow Red */
.hljs-variable,
.hljs-template-variable,
.hljs-tag,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class,
.hljs-regexp,
.hljs-deletion {
	color: #c82829;
}

/* Tomorrow Orange */
.hljs-number,
.hljs-built_in,
.hljs-builtin-name,
.hljs-literal,
.hljs-type,
.hljs-params,
.hljs-meta,
.hljs-link {
	color: #f5871f;
}

/* Tomorrow Yellow */
.hljs-attribute {
	color: #eab700;
}

/* Tomorrow Green */
.hljs-string,
.hljs-symbol,
.hljs-bullet,
.hljs-addition {
	color: #718c00;
}

/* Tomorrow Blue */
.hljs-title,
.hljs-section {
	color: #4271ae;
}

/* Tomorrow Purple */
.hljs-keyword,
.hljs-selector-tag {
	color: #8959a8;
}

.hljs {
	display: block;
	overflow-x: auto;
	color: #4d4d4c;
	padding: 0.5em;
}

.hljs-emphasis {
	font-style: italic;
}

.hljs-strong {
	font-weight: bold;
}
</style>

<style>
/*
 * Markdown PDF CSS
 */

 body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif, "Meiryo";
	padding: 0 12px;
}

pre {
	background-color: #f8f8f8;
	border: 1px solid #cccccc;
	border-radius: 3px;
	overflow-x: auto;
	white-space: pre-wrap;
	overflow-wrap: break-word;
}

pre:not(.hljs) {
	padding: 23px;
	line-height: 19px;
}

blockquote {
	background: rgba(127, 127, 127, 0.1);
	border-color: rgba(0, 122, 204, 0.5);
}

.emoji {
	height: 1.4em;
}

code {
	font-size: 14px;
	line-height: 19px;
}

/* for inline code */
:not(pre):not(.hljs) > code {
	font-size: inherit;
}

/* Page Break : use <div class="page"/> to insert page break
-------------------------------------------------------- */
.page {
	page-break-after: always;
}

</style>

<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
  <script>
    mermaid.initialize({
      startOnLoad: true,
      theme: document.body.classList.contains('vscode-dark') || document.body.classList.contains('vscode-high-contrast')
          ? 'dark'
          : 'default'
    });
  </script>
<h1 id="gii">gii</h1>
<h2 id="%E6%B3%A8%E6%84%8F"><code>注意</code>:</h2>
<ul>
<li>1.使用<code>gii</code>前必须正确配置<code>db</code>,且数据库表至少有字段<code>id int unsigned</code>、<code>is_on tinyint unsigned</code>、<code>version int unsigned</code>、<code>update_time int unsigned</code>字段。</li>
<li>2.<code>gii</code>的路径为<code>http://youhost/gii/gen-code</code>,配置<code>ginMode</code>是<code>release</code>时<code>gii</code>自动禁用，其他<code>gii</code>自动可用。</li>
<li>3.<code>gii</code>会自动读取数据库中所有表，选择某个表后会自动显示对应代码，复制粘贴即可，<code>gii</code>会根据数据库表定义自动选择合适的<code>数据类型</code>、<code>输入校验</code>以及<code>错误提示</code>。</li>
</ul>

<div class="dropdown">
  <button type="button" class="btn dropdown-toggle" id="dropdownMenu1"
		  data-toggle="dropdown">
	  选择表
	  <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
	  <li role="presentation" class="dropdown-header">数据库表</li>
	  {{tableList}}
  </ul>
</div>
<ul>
<li><a href="#model">model</a></li>
<li><a href="#logic">logic</a></li>
<li><a href="#controller">controller</a></li>
</ul>
<h2 id="model">model</h2>
<pre class="hljs"><code><div><span class="hljs-keyword">import</span> (
	<span class="hljs-string">"github.com/gin-gonic/gin"</span>
	<span class="hljs-string">"store/libs/helper"</span>
	<span class="hljs-string">"store/models"</span>
	<span class="hljs-string">"store/models/base"</span>
)

<span class="hljs-keyword">const</span> (
    TABLE_{{TABLE}} = <span class="hljs-string">"{{table}}"</span>
)

<span class="hljs-keyword">type</span> {{Struct}} <span class="hljs-keyword">struct</span> {
{{Properties}}
}

<span class="hljs-comment">/**
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">{{Struct}}Map2Model</span><span class="hljs-params">(data <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">string</span>)</span></span> {{Struct}} {
	<span class="hljs-keyword">return</span> {{Struct}}{
{{map2ModelProperties}}
	}
}

<span class="hljs-comment">/**restful新增数据
 * @email jhq0113@163.com
 * generated by gii
 */</span>
 <span class="hljs-function"><span class="hljs-keyword">func</span></span> {{Struct}}Create(ctx *gin.Context, info <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{}) <span class="hljs-keyword">uint64</span> {
	id := base.NewCommonModel(ctx).Create(TABLE_{{TABLE}}, info)
	return uint64(id)
}

<span class="hljs-comment">/**restful删除，数据库表中必须有id字段
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span></span> {{Struct}}Delete(ctx *gin.Context, id <span class="hljs-keyword">uint64</span>) <span class="hljs-keyword">int64</span> {
	<span class="hljs-keyword">return</span> base.NewCommonModel(ctx).Delete(TABLE_{{TABLE}}, helper.ToString(id))
}

<span class="hljs-comment">/**restful更新(带乐观锁)，数据库表中必须有id,version字段
uint64uint64uint64 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span></span> {{Struct}}Update(ctx *gin.Context, id <span class="hljs-keyword">uint64</span>, version <span class="hljs-keyword">uint64</span>, set <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{}) <span class="hljs-keyword">int64</span> {
	<span class="hljs-keyword">return</span> base.NewCommonModel(ctx).UpdateWithLock(TABLE_{{TABLE}}, helper.ToString(id), version, set)
}

<span class="hljs-comment">/**restful禁用启用，数据库表中必须有is_on字段
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span></span> {{Struct}}UpOrDown(ctx *gin.Context, id <span class="hljs-keyword">uint64</span>, value <span class="hljs-keyword">uint8</span>) <span class="hljs-keyword">int64</span> {
	<span class="hljs-keyword">return</span> base.NewCommonModel(ctx).UpOrDown(TABLE_{{TABLE}}, helper.ToString(id), value)
}

<span class="hljs-comment">/**restful详情，数据库表中必须有id字段
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span></span> {{Struct}}Info(ctx *gin.Context, where <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{}) {{Struct}} {
	info := base.NewCommonModel(ctx).Info(TABLE_{{TABLE}}, where)
	<span class="hljs-keyword">if</span> info != <span class="hljs-literal">nil</span> {
		<span class="hljs-keyword">return</span> {{Struct}}Map2Model(info)
	}
	<span class="hljs-keyword">return</span> {{Struct}}{}
}

<span class="hljs-comment">/**restful列表分页检索
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span></span> {{Struct}}Index(ctx *gin.Context, page <span class="hljs-keyword">int64</span>, pageSize <span class="hljs-keyword">int64</span>, where <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{}, orders []<span class="hljs-keyword">string</span>) <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{} {
	result := base.NewCommonModel(ctx).Index(TABLE_{{TABLE}}, page, pageSize, where, orders)

	<span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(result[<span class="hljs-string">"list"</span>].([]<span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">string</span>)) &gt; <span class="hljs-number">0</span> {
		list := []{{Struct}}{}
		<span class="hljs-keyword">for</span> _, data := <span class="hljs-keyword">range</span> result[<span class="hljs-string">"list"</span>].([]<span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">string</span>) {
			list = <span class="hljs-built_in">append</span>(list, {{Struct}}Map2Model(data))
		}
		result[<span class="hljs-string">"list"</span>] = list
	}

	<span class="hljs-keyword">return</span> result
}
</div></code></pre>
<ul>
<li><a href="#gii">gii</a></li>
</ul>
<h2 id="logic">logic</h2>
<pre class="hljs"><code><div><span class="hljs-keyword">import</span> (
	<span class="hljs-string">"fmt"</span>
	<span class="hljs-string">"github.com/gin-gonic/gin"</span>
	<span class="hljs-string">"store/logic"</span>
	<span class="hljs-string">"store/models"</span>
)

<span class="hljs-keyword">type</span> {{Struct}}Logic <span class="hljs-keyword">struct</span> {
    logic.RestLogic
    Ctx *gin.Context
}

<span class="hljs-keyword">type</span> {{Struct}}Input <span class="hljs-keyword">struct</span> {
	logic.XmlInput
{{inputProperties}}
}

<span class="hljs-comment">/**克隆logic,用于存放*gin.Context
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}}Logic)</span> <span class="hljs-title">Clone</span><span class="hljs-params">(ctx *gin.Context)</span> <span class="hljs-title">logic</span>.<span class="hljs-title">RestLogic</span></span> {
	newLogic := *this
	newLogic.Ctx = ctx
	<span class="hljs-keyword">return</span> &amp;newLogic
}

<span class="hljs-comment">/**解析http输入
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}}Logic)</span> <span class="hljs-title">LoadInput</span><span class="hljs-params">()</span> <span class="hljs-params">(input <span class="hljs-keyword">interface</span>{}, err error)</span></span> {
	in := {{Struct}}Input{
		IsOn: <span class="hljs-number">1</span>,
	}
	err = this.Ctx.ShouldBind(&amp;in)
	<span class="hljs-keyword">return</span> in, err
}

<span class="hljs-comment">/**解析http输入转化为update输入
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}}Logic)</span> <span class="hljs-title">LoadInput4Update</span><span class="hljs-params">(where <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{})</span> <span class="hljs-params">(input <span class="hljs-keyword">interface</span>{}, version <span class="hljs-keyword">uint64</span>, err error)</span></span> {
	model, ok := this.View(where)
	<span class="hljs-keyword">if</span> !ok {
		err = fmt.Errorf(<span class="hljs-string">"not found"</span>)
		<span class="hljs-keyword">return</span>
	}

	val := model.(models.{{Struct}})
	value := {{Struct}}Info2Input(&amp;val)
	err = this.Ctx.ShouldBind(&amp;value)
	input = value
	version = val.Version
	<span class="hljs-keyword">return</span>
}

<span class="hljs-comment">/**创建输入
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}}Logic)</span> <span class="hljs-title">NewCreateInput</span><span class="hljs-params">()</span> <span class="hljs-title">interface</span></span>{} {
	<span class="hljs-keyword">return</span> {{Struct}}Input{
		IsOn: <span class="hljs-number">1</span>,
	}
}

<span class="hljs-comment">/**数据库Model转Input
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">{{Struct}}Info2Input</span><span class="hljs-params">(info *model.{{Struct}})</span></span> {{Struct}}Input {
	<span class="hljs-keyword">return</span> {{Struct}}Input{
{{info2InputProperties}}
	}
}

<span class="hljs-comment">/**插入
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}}Logic)</span> <span class="hljs-title">Add</span><span class="hljs-params">(input <span class="hljs-keyword">interface</span>{})</span> <span class="hljs-params">(id <span class="hljs-keyword">uint64</span>)</span></span> {
	in := input.(*<span class="hljs-keyword">interface</span>{})
	info := logic.Input2Map((*in).({{Struct}}Input))
	<span class="hljs-keyword">return</span> models.{{Struct}}Create(this.Ctx, info)
}

<span class="hljs-comment">/**删除
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}}Logic)</span> <span class="hljs-title">Delete</span><span class="hljs-params">(id <span class="hljs-keyword">uint64</span>)</span> <span class="hljs-params">(rows <span class="hljs-keyword">int64</span>)</span></span> {
	<span class="hljs-keyword">return</span> models.{{Struct}}Delete(this.Ctx, id)
}

<span class="hljs-comment">/**修改
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}}Logic)</span> <span class="hljs-title">Update</span><span class="hljs-params">(version <span class="hljs-keyword">uint64</span>, input <span class="hljs-keyword">interface</span>{})</span> <span class="hljs-params">(rows <span class="hljs-keyword">int64</span>)</span></span> {
	infoInput := input.({{Struct}}Input)
	info := logic.Input2Map(infoInput)
	<span class="hljs-keyword">return</span> models.{{Struct}}Update(this.Ctx, infoInput.Id, version, info)
}

<span class="hljs-comment">/**启用禁用
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}}Logic)</span> <span class="hljs-title">UpOrDown</span><span class="hljs-params">(id <span class="hljs-keyword">uint64</span>, value <span class="hljs-keyword">uint8</span>)</span> <span class="hljs-params">(rows <span class="hljs-keyword">int64</span>)</span></span> {
	<span class="hljs-keyword">return</span> models.{{Struct}}UpOrDown(this.Ctx, id, value)
}

<span class="hljs-comment">/**详情
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}}Logic)</span> <span class="hljs-title">View</span><span class="hljs-params">(where <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{})</span> <span class="hljs-params">(info <span class="hljs-keyword">interface</span>{}, exist <span class="hljs-keyword">bool</span>)</span></span> {
	model := models.{{Struct}}Info(this.Ctx, where)
	<span class="hljs-keyword">return</span> model, model.Id &gt; <span class="hljs-number">0</span>
}

<span class="hljs-comment">/**列表分页检索
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}}Logic)</span> <span class="hljs-title">Index</span><span class="hljs-params">(page <span class="hljs-keyword">int64</span>, pageSize <span class="hljs-keyword">int64</span>, where <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{}, orders []<span class="hljs-keyword">string</span>)</span> <span class="hljs-params">(pageData <span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{})</span></span> {
	<span class="hljs-keyword">return</span> models.{{Struct}}Index(this.Ctx, page, pageSize, where, orders)
}
</div></code></pre>

<h2 id="controller">controller</h2>
<pre class="hljs"><code><div><span class="hljs-keyword">import</span> (
    <span class="hljs-string">"store/libs/controller"</span>
	<span class="hljs-string">"store/logic"</span>
)

<span class="hljs-keyword">type</span> {{Struct}} <span class="hljs-keyword">struct</span> {
	controller.Restful
}

<span class="hljs-comment">/**实例化控制器
 * @email jhq0113@163.com
 * generated by gii
 */</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">New</span></span>{{Struct}}Controller() *{{Struct}} {
	control := <span class="hljs-built_in">new</span>({{Struct}})
	control.Logic = &amp;logic.{{Struct}}Logic{}
	<span class="hljs-keyword">return</span> control
}

<span class="hljs-comment">// @Summary 添加{{Struct}}</span>
<span class="hljs-comment">// @Description 添加{{Struct}}</span>
<span class="hljs-comment">// @Accept  application/json,application/xml</span>
<span class="hljs-comment">// @Produce json,xml</span>
<span class="hljs-comment">// @Tags    {{Struct}}</span>
<span class="hljs-comment">// @Param  {{Struct}}Info   body    logic.{{Struct}}Input     true        "{{Struct}}信息"</span>
<span class="hljs-comment">// @Success 200 {object} controller.Response</span>
<span class="hljs-comment">// @failure 400 {object} controller.Response</span>
<span class="hljs-comment">// @Router /{{struct-route}} [post]</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}})</span> <span class="hljs-title">Post</span><span class="hljs-params">(ctx *gin.Context)</span></span> {
	logic4Ctx := this.Logic.Clone(ctx)
	input, err := logic4Ctx.LoadInput()
	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
		this.Response(ctx, http.StatusBadRequest, this.FormatError(input, err).Error(), <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	id := logic4Ctx.Add(&amp;input)
	<span class="hljs-keyword">if</span> id &lt; <span class="hljs-number">1</span> {
		this.Response(ctx, http.StatusInternalServerError, <span class="hljs-string">"添加失败"</span>, <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	info, _ := logic4Ctx.View(<span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{}{
		<span class="hljs-string">"id"</span>: id,
	})
	this.Response(ctx, http.StatusOK, <span class="hljs-string">"ok"</span>, info)
	<span class="hljs-keyword">return</span>
}

<span class="hljs-comment">// @Summary 删除{{Struct}}</span>
<span class="hljs-comment">// @Description 删除{{Struct}}</span>
<span class="hljs-comment">// @Accept  application/json,application/xml</span>
<span class="hljs-comment">// @Produce json,xml</span>
<span class="hljs-comment">// @Tags    {{Struct}}</span>
<span class="hljs-comment">// @Param  id   query    int     true        "{{Struct}} id"</span>
<span class="hljs-comment">// @Success 200 {object} controller.Response</span>
<span class="hljs-comment">// @failure 400 {object} controller.Response</span>
<span class="hljs-comment">// @Router /{{struct-route}} [delete]</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}})</span> <span class="hljs-title">Delete</span><span class="hljs-params">(ctx *gin.Context)</span></span> {
	id, err := this.GetInfoParams(ctx)
	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
		this.Response(ctx, http.StatusBadRequest, err.Error(), <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	rId := helper.ToInt(id)
	<span class="hljs-keyword">if</span> rId &lt; <span class="hljs-number">0</span> {
		this.Response(ctx, http.StatusBadRequest, <span class="hljs-string">"id最小为1"</span>, <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	this.Logic.Clone(ctx).Delete(<span class="hljs-keyword">uint64</span>(rId))

	this.Response(ctx, http.StatusOK, <span class="hljs-string">"ok"</span>, <span class="hljs-literal">nil</span>)
}

<span class="hljs-comment">// @Summary {{Struct}}禁用与启用</span>
<span class="hljs-comment">// @Description {{Struct}}禁用与启用</span>
<span class="hljs-comment">// @Accept  application/json,application/xml</span>
<span class="hljs-comment">// @Produce json,xml</span>
<span class="hljs-comment">// @Tags    {{Struct}}</span>
<span class="hljs-comment">// @Param  id    query    int     true       "{{Struct}} id"</span>
<span class="hljs-comment">// @Param  value body    int     true        "0禁用，1启用"</span>
<span class="hljs-comment">// @Success 200 {object} controller.Response</span>
<span class="hljs-comment">// @failure 400 {object} controller.Response</span>
<span class="hljs-comment">// @Router /{{struct-route}}/up-or-down [post]</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}})</span> <span class="hljs-title">UpOrDown</span><span class="hljs-params">(ctx *gin.Context)</span></span> {
	id, err := this.GetInfoParams(ctx)
	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
		this.Response(ctx, http.StatusBadRequest, err.Error(), <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	rId := helper.ToInt(id)
	<span class="hljs-keyword">if</span> rId &lt; <span class="hljs-number">0</span> {
		this.Response(ctx, http.StatusBadRequest, <span class="hljs-string">"id最小为1"</span>, <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	val, err := this.GetUpOrDownParams(ctx)
	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
		this.Response(ctx, http.StatusBadRequest, err.Error(), <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	this.Logic.Clone(ctx).UpOrDown(<span class="hljs-keyword">uint64</span>(rId), val)

	this.Response(ctx, http.StatusOK, <span class="hljs-string">"ok"</span>, <span class="hljs-literal">nil</span>)
}

<span class="hljs-comment">// @Summary {{Struct}}禁用与启用</span>
<span class="hljs-comment">// @Description {{Struct}}禁用与启用</span>
<span class="hljs-comment">// @Accept  application/json,application/xml</span>
<span class="hljs-comment">// @Produce json,xml</span>
<span class="hljs-comment">// @Tags    {{Struct}}</span>
<span class="hljs-comment">// @Param  id          query   int                 true        "{{Struct}} id"</span>
<span class="hljs-comment">// @Param  {{Struct}}Info   body    logic.{{Struct}}Input     true        "{{Struct}}信息"</span>
<span class="hljs-comment">// @Success 200 {object} controller.Response</span>
<span class="hljs-comment">// @failure 400 {object} controller.Response</span>
<span class="hljs-comment">// @Router /{{struct-route}} [put]</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}})</span> <span class="hljs-title">Put</span><span class="hljs-params">(ctx *gin.Context)</span></span> {
	id, err := this.GetInfoParams(ctx)
	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
		this.Response(ctx, http.StatusBadRequest, err.Error(), <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	logic4Ctx := this.Logic.Clone(ctx)

	input, version, err := logic4Ctx.LoadInput4Update(<span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{}{
		<span class="hljs-string">"id"</span>: id,
	})

	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
		this.Response(ctx, http.StatusBadRequest, this.FormatError(input, err).Error(), <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	logic4Ctx.Update(version, input)
	info, _ := logic4Ctx.View(<span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{}{
		<span class="hljs-string">"id"</span>: id,
	})

	this.Response(ctx, http.StatusOK, <span class="hljs-string">"ok"</span>, info)
}

<span class="hljs-comment">// @Summary 获取{{Struct}}详情</span>
<span class="hljs-comment">// @Description 获取{{Struct}}详情</span>
<span class="hljs-comment">// @Tags    {{Struct}}</span>
<span class="hljs-comment">// @Accept  json</span>
<span class="hljs-comment">// @Produce json</span>
<span class="hljs-comment">// @Param  id   query    int     true        "{{Struct}} id"</span>
<span class="hljs-comment">// @Success 200 {object} controller.Response</span>
<span class="hljs-comment">// @failure 400 {object} controller.Response</span>
<span class="hljs-comment">// @Router /{{struct-route}} [get]</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}})</span> <span class="hljs-title">Get</span><span class="hljs-params">(ctx *gin.Context)</span></span> {
	id, err := this.GetInfoParams(ctx)

	<span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> {
		this.Response(ctx, http.StatusBadRequest, err.Error(), <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	info, exists := this.Logic.Clone(ctx).View(<span class="hljs-keyword">map</span>[<span class="hljs-keyword">string</span>]<span class="hljs-keyword">interface</span>{}{
		<span class="hljs-string">"id"</span>: id,
	})

	<span class="hljs-keyword">if</span> !exists {
		this.Response(ctx, http.StatusNotFound, <span class="hljs-string">"not found"</span>, <span class="hljs-literal">nil</span>)
		<span class="hljs-keyword">return</span>
	}

	this.Response(ctx, http.StatusOK, <span class="hljs-string">"ok"</span>, info)
}

<span class="hljs-comment">// @Summary 获取{{Struct}}列表</span>
<span class="hljs-comment">// @Description 获取{{Struct}}列表</span>
<span class="hljs-comment">// @Tags    {{Struct}}</span>
<span class="hljs-comment">// @Accept  json</span>
<span class="hljs-comment">// @Produce json</span>
<span class="hljs-comment">// @Param  page       query    int     false        "页码"</span>
<span class="hljs-comment">// @Param  pageSize   query    int     false        "分页大小"</span>
<span class="hljs-comment">// @Success 200 {object} controller.Response</span>
<span class="hljs-comment">// @failure 400 {object} controller.Response</span>
<span class="hljs-comment">// @Router /{{struct-route}}/index [get]</span>
<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-params">(this *{{Struct}})</span> <span class="hljs-title">GetIndex</span><span class="hljs-params">(ctx *gin.Context)</span></span> {
	page, pageSize, where, orders := this.GetIndexParams(ctx)
	result := this.Logic.Clone(ctx).Index(page, pageSize, where, orders)

	this.Response(ctx, http.StatusOK, <span class="hljs-string">"ok"</span>, result)
}
</div></code></pre>

<ul>
<li><a href="#gii">gii</a></li>
</ul>

</body>
</html>
`
)

func renderProperty4Md(fields map[string]base.Field) []byte {
	buf := bytes.NewBufferString("")

	tem := `	{{BigCase}}           <span class="hljs-keyword">{{Type}}</span>  <span class="hljs-string">` + "`" + `json:"{{property}}" xml:"{{property}}"</span>` + "`" + `
`
	for property, field := range fields {
		item := strings.Replace(tem, "{{BigCase}}", field.BigCase, -1)
		item = strings.Replace(item, "{{Type}}", helper.ToString(field.Type), -1)
		item = strings.Replace(item, "{{property}}", property, -1)
		buf.WriteString(item)
	}

	return buf.Bytes()
}

func renderMap2Model4Md(fields map[string]base.Field) []byte {
	buf := bytes.NewBufferString("")

	tem := `		{{BigCase}}:      {{Type}}data[<span class="hljs-string">"{{property}}"</span>]{{end}}
`
	for property, field := range fields {
		t := ""
		end := ")),"
		switch field.Type {
		case reflect.Float64:
			t = `<span class="hljs-keyword">` + helper.ToString(field.Type) + `</span>(helper.ToFloat(`
		case reflect.String:
			end = ","
		default:
			t = `<span class="hljs-keyword">` + helper.ToString(field.Type) + `</span>(helper.ToInt(`
		}

		item := strings.Replace(tem, "{{BigCase}}", field.BigCase, -1)
		item = strings.Replace(item, "{{Type}}", t, -1)
		item = strings.Replace(item, "{{property}}", property, -1)
		item = strings.Replace(item, "{{end}}", end, -1)
		buf.WriteString(item)
	}

	return buf.Bytes()
}

func renderInput4Md(fields map[string]base.Field) []byte {
	buf := bytes.NewBufferString("")

	blackField := map[string]uint8{
		"version":     1,
		"add_time":    1,
		"update_time": 1,
	}

	tem := `	{{BigCase}}         <span class="hljs-keyword">{{Type}}</span>  ` + "`" + `<span class="hljs-string">json:"{{SmallCase}}" xml:"{{SmallCase}}" form:"{{SmallCase}}" field:"{{property}}"{{binding}}{{msg}}</span>` + "`" + `
`
	for property, field := range fields {
		if _, black := blackField[property]; black {
			continue
		}
		item := strings.Replace(tem, "{{BigCase}}", field.BigCase, -1)
		item = strings.Replace(item, "{{Type}}", helper.ToString(field.Type), -1)
		item = strings.Replace(item, "{{SmallCase}}", field.SmallCase, -1)
		item = strings.Replace(item, "{{property}}", property, -1)

		binding := ""
		msg := ""
		switch field.Type {
		case reflect.Uint64, reflect.Uint, reflect.Uint32, reflect.Uint16, reflect.Uint8:
			binding = ` binding:"min=0"`
			msg = ` msg:"` + field.Comment + `必须是非负数"`
		case reflect.String:
			if field.Length > 0 {
				length := helper.ToString(field.Length)
				binding = ` binding:"max=` + length + `"`
				msg = ` msg:"` + field.Comment + `最大长度为` + length + `"`
			}
		}
		item = strings.Replace(item, "{{binding}}", binding, -1)
		item = strings.Replace(item, "{{msg}}", msg, -1)

		buf.WriteString(item)
	}
	return buf.Bytes()
}

func renderInfo2Input4Md(fields map[string]base.Field) []byte {
	buf := bytes.NewBufferString("")
	blackField := map[string]uint8{
		"version":     1,
		"add_time":    1,
		"update_time": 1,
	}
	tem := `		{{BigCase}}:         info.{{BigCase}},
`
	for property, field := range fields {
		if _, black := blackField[property]; black {
			continue
		}
		buf.WriteString(strings.Replace(tem, "{{BigCase}}", field.BigCase, -1))
	}
	return buf.Bytes()
}

func renderTableList(table string) []byte {
	return bytes.Replace([]byte(`<li role="presentation" ><a role="menuitem" tabindex="-1" href="/gii/gen-code?table={{table}}">{{table}}</a></li>`), []byte("{{table}}"), []byte(table), -1)
}
